package com.test.testcompose

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.test.testcompose.page.ButtonAndStateActivity
import com.test.testcompose.page.ListActivity
import com.test.testcompose.ui.theme.TestComposeTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            TestComposeTheme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Column {
                        Greeting(
                            name = "Android",
                            modifier = Modifier.padding(innerPadding),
                        )
                    }
                }
            }
        }
    }

    @Composable
    fun Greeting(
        name: String,
        modifier: Modifier = Modifier,
    ) {
        Column {
            Text(
                text = "Hello $name!",
                modifier = modifier,
            )
            Text(
                text = "ButtonAndStateActivity",
                modifier =
                    modifier.clickable {
                        this@MainActivity.startActivity(
                            Intent(
                                this@MainActivity,
                                ButtonAndStateActivity::class.java,
                            ),
                        )
                    },
            )
            Text(
                text = "ListActivity",
                modifier =
                    modifier.clickable {
                        this@MainActivity.startActivity(
                            Intent(
                                this@MainActivity,
                                ListActivity::class.java,
                            ),
                        )
                    },
            )
        }
    }

    @Preview(showBackground = true)
    @Composable
    fun GreetingPreview() {
        TestComposeTheme {
            Greeting("Android")
        }
    }
}
